﻿using Microsoft.VisualStudio.Diagrams.View;
using Microsoft.VisualStudio.GraphModel;
using Microsoft.VisualStudio.Progression;
using System.Windows;
using System.Windows.Controls;

namespace Timtopia.DGMLPosterView
{
    public class PosterViewAdornerVisualFactory : IVisualFactory
    {
        private IVisualFactory _defaultFactory;
        private GraphControl _control;

        public IVisualFactory DefaultFactory
        {
            get { return _defaultFactory; }
        }

        public PosterViewAdornerVisualFactory(GraphControl control)
        {
            _control = control;
            var vf = control.Diagram.Canvas.VisualFactory as PosterViewVisualFactory;
            if (vf == null)
            {
                _defaultFactory = control.Diagram.Canvas.VisualFactory;
            }
            else
            {
                _defaultFactory = vf.DefaultFactory;
            }
        }

        public void BeginRealize()
        {
            _defaultFactory.BeginRealize();
        }

        public void EndRealize()
        {
            _defaultFactory.EndRealize();
        }

        public System.Windows.Media.Visual Realize(object item, bool force)
        {
            System.Windows.Media.Visual v;
            //GraphLink l = item as GraphLink;
            //l = null;
            //if (l != null && l.IsPseudo && l.Target.IsGroup)
            //{
            //    l.SetLinkTargetDecoratorHeight(0.1);
            //    l.SetLinkTargetDecoratorBaseTipDepth(0.1);
            //    v = _defaultFactory.Realize(item, force);
            //}
            GraphNode node = item as GraphNode;
            if (node != null && node.Id.ToString() == "RenderControl" )
            {
                var button = new Button();
                button.Content = "Tim was here";
                v = button;
            }
            else
            {
                v = _defaultFactory.Realize(item, force);
            }

            return v;
        }

        public bool Virtualize(System.Windows.Media.Visual visual)
        {
            return _defaultFactory.Virtualize(visual);
        }
    }
}
